

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="zh-CN" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="zh-CN" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>WeIdentity Endpoint Service部署指引 &mdash; WeIdentity  文档</title>
  

  
  
  
  

  

  
  
    

  

  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../_static/theme_overrides.css" type="text/css" />
  <link rel="stylesheet" href="../_static/index.css" type="text/css" />
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="next" title="WeIdentity 智能合约设计与实现" href="weidentity-contract-design.html" />
    <link rel="prev" title="WeIdentity Endpoint Service" href="weidentity-endpoint.html" /> 

  
  <script src="../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../index.html" class="icon icon-home"> WeIdentity
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../README.html">什么是 WeIdentity？</a></li>
<li class="toctree-l1"><a class="reference internal" href="one-stop-experience.html">WeIdentity 一站式体验</a></li>
<li class="toctree-l1"><a class="reference internal" href="terminologies.html">术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="use-cases.html">使用场景</a></li>
<li class="toctree-l1"><a class="reference internal" href="weidentity-spec.html">WeIdentity 规范</a></li>
<li class="toctree-l1"><a class="reference internal" href="weidentity-installation.html">WeIdentity Java SDK 安装部署</a></li>
<li class="toctree-l1"><a class="reference external" href="https://weidentity.readthedocs.io/projects/javasdk/zh_CN/latest/">WeIdentity Java SDK 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="weidentity-sample.html">WeIdentity Sample 开发样例</a></li>
<li class="toctree-l1"><a class="reference internal" href="miscellaneous.html">杂项</a></li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="weidentity-rest.html">WeIdentity RestService</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="weidentity-endpoint.html">WeIdentity Endpoint Service</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="weidentity-endpoint.html#endpoint-service">部署Endpoint Service</a><ul class="current">
<li class="toctree-l3 current"><a class="current reference internal" href="#">WeIdentity Endpoint Service部署指引</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#restservice">1. 代理端（RestService）配置</a></li>
<li class="toctree-l4"><a class="reference internal" href="#java-sdk-endpoint">2. 在服务端（Java SDK）注册您的Endpoint</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id1">3. 启动服务端</a></li>
<li class="toctree-l4"><a class="reference internal" href="#endpoint">4. 在代理端调用您的Endpoint</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="weidentity-endpoint.html#id2">使用Endpoint Service</a></li>
<li class="toctree-l2"><a class="reference internal" href="weidentity-endpoint.html#id3">技术细节</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="weidentity-contract-design.html">WeIdentity 智能合约设计与实现</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">WeIdentity</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html">Docs</a> &raquo;</li>
        
          <li><a href="weidentity-endpoint.html">WeIdentity Endpoint Service</a> &raquo;</li>
        
      <li>WeIdentity Endpoint Service部署指引</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="../_sources/docs/weidentity-endpoint-deploy.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="weidentity-endpoint-service">
<h1>WeIdentity Endpoint Service部署指引<a class="headerlink" href="#weidentity-endpoint-service" title="永久链接至标题">¶</a></h1>
<p>为了实现基于RPC的远程调用和转发机制，WeIdentity Endpoint Service分成两部分：代理端（也即RestService这一侧）和服务端（也即Java SDK这一侧）。</p>
<p>其中，代理端负责直接接收HTTP/HTTPS请求，解析、进行Endpoint查询，并转发给对应的服务端。服务端负责接收请求，并直接转发给预先注册的Endpoint实现。因此，您需要按照以下顺序，分别部署Endpoint Service的服务端和代理端。</p>
<div class="section" id="restservice">
<h2>1. 代理端（RestService）配置<a class="headerlink" href="#restservice" title="永久链接至标题">¶</a></h2>
<p>Endpoint Service在代理端是内建于Rest Service的，环境要求也与其一致，因此您需要首先按照 <a class="reference external" href="./weidentity-rest-deploy.html">Rest Service 部署文档</a>的步骤对其进行部署。</p>
<p>部署完毕后，在 <code class="docutils literal notranslate"><span class="pre">dist/conf</span></code> 目录下，修改 <code class="docutils literal notranslate"><span class="pre">application.properties</span></code> 文件中的主机端口列表（<code class="docutils literal notranslate"><span class="pre">server.hostport.list</span></code>）这一项。您需要在此处以逗号分隔所有需要由Rest Service连接的远程服务端，指明其主机IP及端口。这样，Endpoint Service就会在后台以您配置的时间间隔（此处的 <code class="docutils literal notranslate"><span class="pre">fetch.period.seconds</span></code> ）去远程拉取注册在服务端的Endpoint。</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="c1"># 向服务端周期拉取Endpoint配置的时间间隔，单位为秒</span>
fetch.period.seconds<span class="o">=</span><span class="m">60</span>
<span class="c1"># 服务端所有主机端口列表</span>
server.hostport.list<span class="o">=</span><span class="m">127</span>.0.0.1:6010,127.0.0.2:6011
</pre></div>
</div>
</div>
<div class="section" id="java-sdk-endpoint">
<h2>2. 在服务端（Java SDK）注册您的Endpoint<a class="headerlink" href="#java-sdk-endpoint" title="永久链接至标题">¶</a></h2>
<p>Rest Service代理端，仅仅是一个收集来自各方端点请求并进行中转的角色，它不包含具体的Endpoint的处理逻辑和方法实现。每个主机仍然需要在自己的Java SDK侧注册Endpoint，并暴露之前在代理端声明的对外端口，以供代理端中转调用。您需要在您集成Java-SDK时执行以下步骤：</p>
<ul class="simple">
<li><dl class="simple">
<dt>为您需要注册的每个Endpoint，实现一个对应的 <code class="docutils literal notranslate"><span class="pre">EndpointFunctor</span></code> 接口。此接口包括两个方法： <code class="docutils literal notranslate"><span class="pre">execute()</span></code> 和 <code class="docutils literal notranslate"><span class="pre">getDescription()</span></code></dt><dd><ul>
<li><p>实现 <code class="docutils literal notranslate"><span class="pre">execute()</span></code> ，用来决定具体当代理端的RPC请求发送过来时需要进行的操作</p></li>
<li><p>实现 <code class="docutils literal notranslate"><span class="pre">getDescription()</span></code> ，用来提供一段对此接口功能的描述</p></li>
</ul>
</dd>
</dl>
</li>
<li><p>在实现完成之后，通过 <code class="docutils literal notranslate"><span class="pre">registerEndpoint()</span></code> 方法向此EndpointHandler内注册您的Endpoint</p></li>
<li><p>服务端会自动将您的Endpoint写入本地Endpoint数据配置项中</p></li>
<li><p>本地Endpoint数据配置项会被周期性地同步到代理端</p></li>
<li><p>为了确保代理端能够正确地获取这些Endpoint，您需要启动 <code class="docutils literal notranslate"><span class="pre">RpcServer</span></code> 的 <code class="docutils literal notranslate"><span class="pre">main()</span></code> 进程</p></li>
</ul>
<p>详细的相关实现，可以参考源代码的 <a class="reference external" href="https://github.com/WeBankBlockchain/WeIdentity-Sample/blob/master/src/main/java/com/webank/weid/demo/command/EndpointSample.java">EndpointSample.java</a> 。</p>
</div>
<div class="section" id="id1">
<h2>3. 启动服务端<a class="headerlink" href="#id1" title="永久链接至标题">¶</a></h2>
<p>Endpoint Service在服务端依托于WeIdentity-Java-SDK，环境要求也与其一致，请见 <a class="reference external" href="./weidentity-installation.html">Java-SDK 部署环境要求</a>。</p>
<p>在 <code class="docutils literal notranslate"><span class="pre">src/main/resources</span></code> 目录下，修改 <code class="docutils literal notranslate"><span class="pre">weidentity.properties</span></code> 文件中的 <code class="docutils literal notranslate"><span class="pre">rpc.listener.port</span></code> 这一项内容，以具体确定在哪个端口上进行监听。</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="c1"># RPC服务端的监听端口</span>
rpc.listener.port<span class="o">=</span><span class="m">6010</span>
</pre></div>
</div>
<p>随后，您需要执行您在上一步骤中注册Endpoint的方法。以 <code class="docutils literal notranslate"><span class="pre">EndpointSample.java</span></code> 为例，执行：</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>java -cp &lt;<span class="nv">$your</span> class path&gt; com.webank.weid.suite.endpoint.EndpointSample
</pre></div>
</div>
<p>您也可以在IDE环境里执行您的注册方法。当您看到以下提示，表示RPC Server已经启动完毕：</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>Trying to receive incoming traffic at Port: 6010
</pre></div>
</div>
</div>
<div class="section" id="endpoint">
<h2>4. 在代理端调用您的Endpoint<a class="headerlink" href="#endpoint" title="永久链接至标题">¶</a></h2>
<p>当您注册Endpoint完毕之后，等待您之前所设定的拉取时间间隔（默认为60秒），以保证此Endpoint被代理端正确地拉取到。随后，您就可以在代理端调用此接口了。</p>
<p>您可以参见<a class="reference external" href="./weidentity-endpoint-deploy.html">REST API文档</a>中的“WeIdentity Endpoint Service API”一节，了解如何获取和调用注册的Endpoint。</p>
</div>
</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="weidentity-contract-design.html" class="btn btn-neutral float-right" title="WeIdentity 智能合约设计与实现" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="weidentity-endpoint.html" class="btn btn-neutral" title="WeIdentity Endpoint Service" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright (2018) WeBank Co., Ltd.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    
    
      <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
        <script src="../_static/jquery.js"></script>
        <script src="../_static/underscore.js"></script>
        <script src="../_static/doctools.js"></script>
        <script src="../_static/language_data.js"></script>
        <script src="../_static/translations.js"></script>
    

  

  <script type="text/javascript" src="../_static/js/theme.js"></script>

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>